package com.edu.web.controller.info;

import com.edu.common.annotation.Log;
import com.edu.common.core.controller.BaseController;
import com.edu.common.core.domain.AjaxResult;
import com.edu.common.core.page.TableDataInfo;
import com.edu.common.enums.BusinessType;
import com.edu.common.utils.poi.ExcelUtil;
import com.edu.framework.websocket.assemble.message.TriggerMsgEngine;
import com.edu.framework.websocket.service.ExamSeatService;
import com.edu.framework.websocket.service.ForceNoticeService;
import com.edu.framework.websocket.service.NoticeService;
import com.edu.system.domain.TNotice;
import com.edu.system.domain.TPublishClass;
import com.edu.system.domain.req.PublishDTO;
import com.edu.system.service.ITNoticeService;
import com.edu.system.service.ITPublishClassService;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * 
 * @author xxxx
 * @date 2023-12-27
 */
@Slf4j
@RestController
@RequestMapping("/publish/record")
public class PublishRecordController extends BaseController
{
    @Resource
    private ITPublishClassService publishClassService;
    @Resource
    private NoticeService wsNoticeService;
    @Resource
    private ForceNoticeService wsForceNoticeService;
    @Resource
    private ExamSeatService wsExamSeatService;


    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPublishClass publishClass)
    {
        startPage();

        if (publishClass.getType() != null && publishClass.getType().equals(1)){
            publishClass.setNoticeType(1);
        }

        if (publishClass.getType() != null && publishClass.getType().equals(99)){
            publishClass.setType(1);
            publishClass.setNoticeType(2);
        }

        List<TPublishClass> list = publishClassService.selectTPublishClassList(publishClass);
        return getDataTable(list);
    }

    /**
     * 删除发布
     */
    @Log(title = "删除发布", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        int i = publishClassService.deleteTPublishClassByIds(ids);

        CompletableFuture.runAsync(() -> {
            wsNoticeService.pushMsg(new ArrayList<>());
            wsForceNoticeService.pushMsg(new ArrayList<>());
            wsExamSeatService.pushMsg(new ArrayList<>());
        });

        return toAjax(i);
    }

}
